package com.xgc.book.bookserver.util;

import lombok.Data;

/**
 * @Author PangJunjie
 * @Date 2023/9/14/014
 */
@Data
public class ResultJson {
    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;
    private static final String SUCCESS_MSG = "success";
    private static final String ERROR_MSG = "error";


    private Integer code;
    private String msg;
    private Object data;

    public ResultJson() {
        this.code = SUCCESS_CODE;
        this.msg = SUCCESS_MSG;
    }

    public static ResultJson ok() {
        return new ResultJson();
    }

    public static ResultJson ok(Object data) {
        ResultJson resultJson = new ResultJson();
        resultJson.setData(data);
        return resultJson;
    }

    public static ResultJson error(Integer code) {
        return error(code, ERROR_MSG);
    }

    public static ResultJson error(Integer code, String msg) {
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(code);
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson error(String msg) {
        return error(ERROR_CODE, msg);
    }

    public static ResultJson error() {
        return error(ERROR_CODE, "error");
    }
}
